$(function() {
    var integral = 180;
    var jncoin = 1128;

    $.ajax({
        type: 'GET',
        url: serverPort + '/ddApi/socialOb/getSocialUserInfo?openId=' + openId,
        dataType: 'json',
        success: function(res) {
           var userData =  res.data
           console.log(userData)
           $(".ie-header img").attr("src", userData.headUrl);
           integral = userData.integral;
           $(".ie-header span").text(userData.nickName);
           $("div[rel=integral],i[rel=integral]").text(integral);
           $("input[name=num]").val(integral);
        },
        error: function(res) {
            console.log(res)
        }
    })

    $(".ie-exchange span").click(function(){
        var num = parseInt($("input[name=num]").val());
        var opr = $(this).attr("rel");
        if(opr=="minus") num--;
        else num++;
        if(num>0 && num<=integral) $("input[name=num]").val(num);
    });

    $(".ie-exchange a").click(function() {
        var num = parseInt($("input[name=num]").val());
        if(num>integral || integral==0) return false;
        integral -= num;
        jncoin += num;
        $("div[rel=integral],i[rel=integral]").text(integral);
        $("input[name=num]").val(integral);
        $("div[rel=jncoin]").text(jncoin);
        alert('兑换成功');
    });
})